from flask import Flask

#定义注册蓝图方法
def reg_blueprint(app):
    from app.api.v1 import create_blueprint_v1
    #传入公用蓝图创建方法(create_blueprint_v1())创建的蓝图对象
    app.register_blueprint(create_blueprint_v1(), url_prefix='/v1')

#注册插件(数据库关联)
def reg_plugin(app):
    from app.models.base import db
    db.init_app(app)
    #create_all要放到app上下文环境中使用
    with app.app_context():
        db.create_all()

def create_app():
    app = Flask(__name__)
    app.config.from_object('app.config.secure')    #重要参数配置(secure.py)
    app.config.from_object('app.config.setting')   #基本配置(setting.py)
    #注册蓝图与app对象相关联
    reg_blueprint(app)
    #注册插件(数据库)与app对象相关联
    reg_plugin(app)
    #一定要记得返回app
    return app

